package com.hyq.learn.common.util;

/**
 * @author xiaoyuqin
 */
public class RandomUtil {
    private static final String CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static String randomString(int length) {
        char[] charArray = CHARS.toCharArray();
        StringBuilder result = new StringBuilder();
        for (int i = length; i > 0; --i) {
            double random = Math.random();
            int index = (int) Math.floor(random * CHARS.length());
            result.append(charArray[index]);
        }
        return result.toString();
    }

}
